// BranchTable.cpp: implementation of the BranchTable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BranchTable.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace PDMS
{
	namespace PDMSDBIF
	{
		BEGIN_REGISTER_MAP( BranchTable, MultiRecordsDatabaseElement)
			REGISTER( _T("BranchData"), GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) )
		END_REGISTER_MAP();

		BranchTable::BranchTable()
		{
			
		}
		
		BranchTable::~BranchTable()
		{
			
		}
		
		unsigned long BranchTable::GetID()
		{
			return m_ResPtr->GetLong( _T("ID") );
		}
		
		void BranchTable::SetID( unsigned long lID )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetID( lID );
		}
		
		const TemperatureUnit BranchTable::GetTemperature()
		{
			double dbuf;
			dbuf = m_ResPtr->GetDouble( _T("Temperature") );
			return TemperatureUnit( dbuf );
		}
		
		void BranchTable::SetTemperature( const TemperatureUnit& buf)
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTemperature( buf );
		}
		
		BOOL BranchTable::GetBuildFlag()
		{
			return m_ResPtr->GetBool( _T("BuildFlag") );
		}
		
		void BranchTable::SetBuilFlag( BOOL bflag )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetBuilFlag( bflag );
		}
		
		BOOL BranchTable::GetShopFlag()
		{
			return m_ResPtr->GetBool( _T("ShopFlag") );
		}
		
		void BranchTable::SetShopFlag( BOOL bflag )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetShopFlag( bflag );
		}
		
		const LengthUnit BranchTable::GetHeadBore()
		{
			return LengthUnit( m_ResPtr->GetDouble( _T("HeadBore") ) );
		}
		
		void BranchTable::SetHeadBore( const LengthUnit& dbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetHeadBore( dbuf );
		}
		
		const LengthUnit BranchTable::GetTailBore()
		{
			return LengthUnit( m_ResPtr->GetDouble( _T("TailBore") ) );
		}
		
		void BranchTable::SetTailBore( const LengthUnit& dbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTailBore( dbuf );
		}
		
		const UeGeVector3d BranchTable::GetHeadDir()
		{
			double dxdir = m_ResPtr->GetDouble( _T("HeadDir_X") );
			double dydir = m_ResPtr->GetDouble( _T("HeadDir_Y") );
			double dzdir = m_ResPtr->GetDouble( _T("HeadDir_Z") );
			return UeGeVector3d( dxdir, dydir, dzdir );
		}
		
		void BranchTable::SetHeadDir( const UeGeVector3d& bufvec )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetHeadDir( bufvec );
		}
		
		const UeGePoint3d BranchTable::GetHeadPos()
		{
			double dxpos = m_ResPtr->GetDouble( _T("HeadPos_X") );
			double dypos = m_ResPtr->GetDouble( _T("HeadPos_Y") );
			double dzpos = m_ResPtr->GetDouble( _T("HeadPos_Z") );
			return UeGePoint3d( dxpos, dypos, dzpos );
		}
		
		void BranchTable::SetHeadPos( const UeGePoint3d& bufpos )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetHeadPos( bufpos );
		}
		
		const PressureUnit BranchTable::GetPressure()
		{
			double dpressure = m_ResPtr->GetDouble( _T("Pressure") );
			return PressureUnit( dpressure );
		}
		
		void BranchTable::SetPressure( const PressureUnit& buf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetPressure( buf );
		}
		
		const StdString BranchTable::GetCaseRef()
		{
			return m_ResPtr->GetString( _T("CaseRef") );
		}
		
		void BranchTable::SetCaseRef( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetCaseRef( strbuf );
		}
		
		const StdString BranchTable::GetDescription()
		{
			return m_ResPtr->GetString( _T("Description") );
		}
		
		void BranchTable::SetDescription( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetDescription( strbuf );
		}
		
		const StdString BranchTable::GetFluRef()
		{
			return m_ResPtr->GetString( _T("Fluref") );
		}
		
		void BranchTable::SetFluRef( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetFluRef( strbuf );
		}
		const StdString BranchTable::GetFunction()
		{
			return m_ResPtr->GetString( _T("Fuction") );
		}
		
		void BranchTable::SetFunction( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetFunction( strbuf );
		}
		
		const StdString BranchTable::GetHeadConn()
		{
			return m_ResPtr->GetString( _T("HConn") );
		}
		
		void BranchTable::SetHeadConn( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetHeadConn( strbuf );
		}
		
		const StdString BranchTable::GetHeadRef()
		{
			return m_ResPtr->GetString( _T("HRef") );
		}
		
		void BranchTable::SetHeadRef( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetHeadRef( strbuf );
		}
		
		const StdString BranchTable::GetHstube()
		{
			return m_ResPtr->GetString( _T("HStube") );
		}
		
		void BranchTable::SetHstube( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetHstube( strbuf );
		}
		
		const StdString BranchTable::GetIspec()
		{
			return m_ResPtr->GetString( _T("Ispec") );
		}
		
		void BranchTable::SetIspec( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetIspec( strbuf );
		}
		
		const StdString BranchTable::GetMatRef()
		{
			return m_ResPtr->GetString( _T("Matref") );
		}
		
		void BranchTable::SetMatRef( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetMatRef( strbuf );
		}
		
		const StdString BranchTable::GetPspec()
		{
			return m_ResPtr->GetString( _T("Pspec") );
		}
		
		void BranchTable::SetPspec( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetPspec( strbuf );
		}
		
		const StdString BranchTable::GetPurpose()
		{
			return m_ResPtr->GetString( _T("Purpose") );
		}
		
		void BranchTable::SetPurpose( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetPurpose( strbuf );
		}
		
		const StdString BranchTable::GetTailConn()
		{
			return m_ResPtr->GetString( _T("TConn") );
		}
		
		void BranchTable::SetTailConn( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTailConn( strbuf );
		}
		
		const StdString BranchTable::GetTailRef()
		{
			return m_ResPtr->GetString( _T("TRef") );
		}
		
		void BranchTable::SetTailRef( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTailRef( strbuf );
		}
		
		const StdString BranchTable::GetTspec()
		{
			return m_ResPtr->GetString( _T("Tspec") );
		}
		
		void BranchTable::SetTspec( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTspec( strbuf );
		}
		
		unsigned long BranchTable::GetParentID()
		{
			return m_ResPtr->GetLong( _T("ParentID") );
		}
		
		void BranchTable::SetParentID( unsigned long lID)
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetParentID( lID );
		}
		
		const StdString BranchTable::GetPaintRef()
		{
			return m_ResPtr->GetString( _T("Ptspec") );
		}
		
		void BranchTable::SetPaintRef( const StdString& strbuf )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetPaintRef( strbuf );
		}
		
		const UeGePoint3d BranchTable::GetTailPos()
		{
			double dxpos = m_ResPtr->GetDouble( _T("TailPos_X") );
			double dypos = m_ResPtr->GetDouble( _T("TailPos_Y") );
			double dzpos = m_ResPtr->GetDouble( _T("TailPos_Z") );
			return UeGePoint3d( dxpos, dypos, dzpos );
		}

		void BranchTable::SetTailPos( const UeGePoint3d& tpos )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTailPos( tpos );
		}

		const UeGeVector3d BranchTable::GetTailDir()
		{
			double dxdir = m_ResPtr->GetDouble( _T("TailDir_X") );
			double dydir = m_ResPtr->GetDouble( _T("TailDir_Y") );
			double dzdir = m_ResPtr->GetDouble( _T("TailDir_Z") );
			return UeGeVector3d( dxdir, dydir, dzdir );
		}

		void BranchTable::SetTailDir( const UeGeVector3d& tdir )
		{
			ASSERT( m_pCurRecord != NULL );
			m_pCurRecord->SetTailDir( tdir );
		}
		
		StdString BranchTable::GetOpenSQL( const StdString& strCondition )
		{
			StdString strTemp( _T("Select * from BranchData") );
			if ( ALLRECORD == strCondition )
			{
				return strTemp; 
			}
			return strTemp + _T(" Where ") + strCondition;
		}

		StdString BranchTable::GetTableName()
		{
			return StdString( _T("BranchData") );
		}
		
		void BranchTable::SetData( RecordPtr_ ptr )
		{
			ASSERT( ptr != NULL );
			
			m_ResPtr->SetLong( _T("ID"), ptr->GetID() );
			m_ResPtr->SetBool( _T("BuildFlag"), ptr->GetBuildFlag() ? true : false );
			m_ResPtr->SetBool( _T("ShopFlag"), ptr->GetShopFlag() ? true : false );
			m_ResPtr->SetString( _T("CaseRef"), ptr->GetCaseRef() );
			m_ResPtr->SetString( _T("Description"), ptr->GetDescription() );
			m_ResPtr->SetString( _T("Fluref"), ptr->GetFluRef() );
			m_ResPtr->SetString( _T("Fuction"), ptr->GetFunction() );
			m_ResPtr->SetDouble( _T("HeadBore"), ptr->GetHeadBore().GetValue() );
			m_ResPtr->SetDouble( _T("TailBore"), ptr->GetTailBore().GetValue() );
			m_ResPtr->SetString( _T("HConn"), ptr->GetHeadConn() );
			m_ResPtr->SetString( _T("HRef"), ptr->GetHeadRef() );
			m_ResPtr->SetDouble( _T("HeadDir_X"), ptr->GetHeadDir().x );
			m_ResPtr->SetDouble( _T("HeadDir_Y"), ptr->GetHeadDir().y );
			m_ResPtr->SetDouble( _T("HeadDir_Z"), ptr->GetHeadDir().z );
			m_ResPtr->SetDouble( _T("HeadPos_X"), ptr->GetHeadPos().x );
			m_ResPtr->SetDouble( _T("HeadPos_Y"), ptr->GetHeadPos().y );
			m_ResPtr->SetDouble( _T("HeadPos_Z"), ptr->GetHeadPos().z );
			m_ResPtr->SetDouble( _T("TailPos_X"), ptr->GetTailPos().x );
			m_ResPtr->SetDouble( _T("TailPos_Y"), ptr->GetTailPos().y );
			m_ResPtr->SetDouble( _T("TailPos_Z"), ptr->GetTailPos().z );
			m_ResPtr->SetDouble( _T("TailDir_X"), ptr->GetTailDir().x );
			m_ResPtr->SetDouble( _T("TailDir_Y"), ptr->GetTailDir().y );
			m_ResPtr->SetDouble( _T("TailDir_Z"), ptr->GetTailDir().z );
			m_ResPtr->SetString( _T("HStube"), ptr->GetHstube() );
			m_ResPtr->SetDouble( _T("Pressure"), ptr->GetPressure().GetValue() );
			m_ResPtr->SetString( _T("Ispec"), ptr->GetIspec() );
			m_ResPtr->SetString( _T("Matref"), ptr->GetMatRef() );
			m_ResPtr->SetString( _T("Pspec"), ptr->GetPspec() );
			m_ResPtr->SetString( _T("Ptspec"), ptr->GetPaintRef() );
			m_ResPtr->SetString( _T("Purpose"), ptr->GetPurpose() );
			m_ResPtr->SetString( _T("TConn"), ptr->GetTailConn() );
			m_ResPtr->SetString( _T("TRef"), ptr->GetTailRef() );
			m_ResPtr->SetString( _T("Tspec"), ptr->GetTspec() );
			m_ResPtr->SetDouble( _T("Temperature"), ptr->GetTemperature().GetValue() );
			m_ResPtr->SetLong( _T("ParentID"), ptr->GetParentID() );
				
		}
	}
}


